package day03.text02;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class MyRunable implements Runnable  {


    private AtomicInteger ai = new AtomicInteger(10);

    private AtomicInteger start = new AtomicInteger(0);

    private String  first ="";

    private Object object = new Object();
    @Override
    public void run() {


        while (true) {
            synchronized (object) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (start.get() >= 50) {
                    if (first.equals(Thread.currentThread().getName())) {
                        System.out.println(first + "最高为" + ai);
                        break;
                    }


                } else {
                    ai.addAndGet(new Random().nextInt(900) + 100);
                    first = Thread.currentThread().getName();
                    System.out.println(Thread.currentThread().getName() + "拍为" + ai);
                    start.incrementAndGet();

                }
            }
        }
    }



}